package com.sunyard.manage.apk;

import java.util.Base64;

/**
 * @author: ZhangShuai
 * @description:
 * @create: 2022-07-20 16:20
 **/
public class Base64Jdk {
    public static String decode(String base64) {
        Base64.Decoder decoder = Base64.getDecoder();
        byte[] bytes = decoder.decode(base64);
        System.out.println("BASE64解密：" + new String(new byte[]{bytes[0], bytes[1]}));
        System.out.println("BASE64解密：" + new String(bytes));
        return new String(bytes);
    }

    public static String subString(String str, String strStart, String strEnd) {
        String tempStr;
        tempStr = str.substring(str.indexOf(strStart), str.lastIndexOf(strEnd) + 2);
        return tempStr;
    }

    public static byte[] hexStr2Bytes(String hexStr) {
        String str = "0123456789ABCDEF";
        char[] hexs = hexStr.toCharArray();
        byte[] bytes = new byte[hexStr.length() / 2];
        int n;

        for (int i = 0; i < bytes.length; i++) {
            n = str.indexOf(hexs[2 * i]) * 16;
            n += str.indexOf(hexs[2 * i + 1]);
            bytes[i] = (byte) (n & 0xff);
        }
        return bytes;
    }
}
